package ldh.im.base.handler;

import io.netty.channel.*;
import ldh.im.dto.base.SuccessResp;
import ldh.im.dto.business.ExitReq;
import ldh.im.util.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ChannelHandler.Sharable
public class ExitHandler extends SimpleChannelInboundHandler<ExitReq> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExitHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ExitReq exitReq) throws Exception {
        LOGGER.info(String.format("exitReq data: %s", JsonUtil.toJson(exitReq)));
        SuccessResp rec = new SuccessResp(exitReq.getLocalSeq());
        ChannelFuture channelFuture = ctx.channel().writeAndFlush(rec);
        channelFuture.addListener(ChannelFutureListener.CLOSE);
    }

}
